package com.zhika.zishi.customview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zhika.zishi.R;
import com.zhika.zishi.interfaces.Bottom2Interface;

/**
 * Created by shi-02 on 2015/4/9.
 */
public class Bottom2View extends FrameLayout implements View.OnClickListener{

    private static final String TAG = "Bottom2View";
    private View view;

    private LayoutInflater inflater;

    private Context context;

    private RelativeLayout leftLayout;
    private ImageView leftImageView;
    private TextView leftTextView;


    private RelativeLayout middleLeftLayout;
    private ImageView middleLeftImageView;
    private TextView middleLeftText;

    private RelativeLayout middleRightLayout;
    private ImageView middleRightImageView;
    private TextView middleRightTextView;

    private RelativeLayout rightLayout;
    private ImageView rightImageView;
    private TextView rightTextView;

    //点击事件的接口
    private Bottom2Interface bottom2Interface;

    public void setBottom2Interface(Bottom2Interface bottom2Interface){
        this.bottom2Interface = bottom2Interface;
    }

    public Bottom2View(Context context) {
        this(context, null);
    }

    public Bottom2View(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public Bottom2View(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        this.context = context;
        initView();

    }

    private void initView(){
        view = inflater.from(context).inflate(R.layout.bottom_2_view,this);

        leftLayout = (RelativeLayout) view.findViewById(R.id.bottom_2_left_layout);
        leftLayout.setOnClickListener(this);
        leftImageView = (ImageView) view.findViewById(R.id.bottom_2_left_image_view);
        leftTextView = (TextView) view.findViewById(R.id.bottom_2_left_text);

        middleLeftLayout = (RelativeLayout) view.findViewById(R.id.bottom_2_middle_l_layout);
        middleLeftLayout.setOnClickListener(this);
        middleLeftImageView = (ImageView) view.findViewById(R.id.bottom_2_middle_l_image_view);
        middleLeftText = (TextView) view.findViewById(R.id.bottom_2_middle_l_text);

        middleRightLayout = (RelativeLayout) view.findViewById(R.id.bottom_2_middle_r_layout);
        middleRightLayout.setOnClickListener(this);
        middleRightImageView = (ImageView) view.findViewById(R.id.bottom_2_middle_r_image_view);
        middleRightTextView = (TextView) view.findViewById(R.id.bottom_2_middle_r_text);

        rightLayout = (RelativeLayout) view.findViewById(R.id.bottom_2_right_layout);
        rightLayout.setOnClickListener(this);
        rightImageView = (ImageView) view.findViewById(R.id.bottom_2_right_image_view);
        rightTextView = (TextView) view.findViewById(R.id.bottom_2_right_text);


    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.bottom_2_left_layout:
                bottom2Interface.leftBottom2Listener();
                break;
            case R.id.bottom_2_middle_l_layout:
                bottom2Interface.middleLeftBottom2Listener();
                break;
            case R.id.bottom_2_middle_r_layout:
                bottom2Interface.middleRightBottom2Listener();
                break;
            case R.id.bottom_2_right_layout:
                bottom2Interface.rightBottom2Listener();
                break;
            default:
                break;
        }
    }

    /**
     * 隐藏中右的布局
     */
    public void hideMiddleRightLayout(){
        middleRightLayout.setVisibility(GONE);
    }

    /**
     * 修改左边布局的text内容
     * @param msg
     */
    public void setLeftLayoutText(String msg){
        leftTextView.setText(msg);
    }

    /**
     * 修改中左边布局的text内容
     * @param msg
     */
    public void setMiddleLeftLayoutText(String msg){
        middleLeftText.setText(msg);
    }

    /**
     * 修改中右边布局的text内容
     * @param msg
     */
    public void setMiddleRightLayoutText(String msg){
        middleRightTextView.setText(msg);
    }

    /**
     * 修改右边布局的text内容
     * @param msg
     */
    public void setRightLayoutText(String msg){
        rightTextView.setText(msg);
    }
}
